package com.ruoyi.web.controller.map;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruoyi.map.demo.util.HttpUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.map.domain.AdviceFeedback;
import com.ruoyi.map.service.IAdviceFeedbackService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户意见反馈Controller
 *
 * @author dihang
 * @date 2023-08-14
 */
@Api(value = "小程序意见反馈",tags = {"小程序意见反馈"})
@RestController
@RequestMapping("/map/feedback")
public class AdviceFeedbackController extends BaseController
{
    @Autowired
    private IAdviceFeedbackService adviceFeedbackService;


    /**
     * 获取物流信息详细信息
     */
    @ApiOperation(value = "获取用户意见反馈详细信息")
//    @PreAuthorize("@ss.hasPermi('heng:logistics:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        AdviceFeedback adviceFeedback = adviceFeedbackService.selectId(id);
        return AjaxResult.success(adviceFeedback);
    }






    @ApiOperation(value = "身份验证")
    @GetMapping("/test/{name}/{idNo}")
    public AjaxResult ceshi(@PathVariable String name,@PathVariable String idNo) {
        String host = "https://idenauthen.market.alicloudapi.com";
        String path = "/idenAuthentication";
        String method = "POST";
        String appcode = "f13835a209b24e74a243105436ab72e5";
        Map<String, String> headers = new HashMap<String, String>();
        //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
        headers.put("Authorization", "APPCODE " + appcode);
        //根据API的要求，定义相对应的Content-Type
        headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
        Map<String, String> querys = new HashMap<String, String>();
        Map<String, String> bodys = new HashMap<String, String>();
        bodys.put("idNo", idNo);
        bodys.put("name", name);
        Object result = new Object();


        try {
            /**
             * 重要提示如下:
             * HttpUtils请从
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
             * 下载
             *
             * 相应的依赖请参照
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
             */
            HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
            System.out.println(response.toString());
            //获取response的body
            result = EntityUtils.toString(response.getEntity());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return AjaxResult.success(result);
    }


    /**
     * 查询用户意见反馈列表
     */
    @ApiOperation(value = "查询用户意见反馈列表")
//    @PreAuthorize("@ss.hasPermi('map:feedback:list')")
    @GetMapping("/list")
    public IPage<AdviceFeedback> list(AdviceFeedback adviceFeedback)
    {
        return adviceFeedbackService.selectAdviceFeedbackList(adviceFeedback);
    }

    /**
     * 导出用户意见反馈列表
     */
//    @PreAuthorize("@ss.hasPermi('map:feedback:export')")
    @Log(title = "用户意见反馈", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response)
    {
        List<AdviceFeedback> list = adviceFeedbackService.list();
        ExcelUtil<AdviceFeedback> util = new ExcelUtil<AdviceFeedback>(AdviceFeedback.class);
        util.exportExcel(response, list, "用户意见反馈数据");
    }

//    /**
//     * 获取用户意见反馈详细信息
//     */
//    @ApiOperation(value = "获取用户意见反馈详细信息")
////    @PreAuthorize("@ss.hasPermi('map:feedback:query')")
//    @GetMapping(value = "/{id}")
//    public AjaxResult getInfo(@PathVariable("id") Long id) {
//        return AjaxResult.success(adviceFeedbackService.getById(id));
//    }

    /**
     * 新增用户意见反馈
     */
    @ApiOperation(value = "新增用户意见反馈")
//    @PreAuthorize("@ss.hasPermi('map:feedback:add')")
    @Log(title = "用户意见反馈", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AdviceFeedback adviceFeedback) {
        return toAjax(adviceFeedbackService.save(adviceFeedback));
    }

    /**
     * 修改用户意见反馈
     */
    @ApiOperation(value = "修改用户意见反馈")
//    @PreAuthorize("@ss.hasPermi('map:feedback:edit')")
    @Log(title = "用户意见反馈", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AdviceFeedback adviceFeedback) {
        return toAjax(adviceFeedbackService.updateById(adviceFeedback));
    }

    /**
     * 删除用户意见反馈
     */
    @ApiOperation(value = "删除用户意见反馈")
//    @PreAuthorize("@ss.hasPermi('map:feedback:remove')")
    @Log(title = "用户意见反馈", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(adviceFeedbackService.removeByIds(Arrays.asList(ids)));
    }
}
